<template>
  <body>
    <el-form :model="form" style="width: 600px">
      <el-form-item label="用户名称:">
        <el-input v-model="form.userName" />
      </el-form-item>
      <el-form-item label="密码:">
        <el-input v-model="form.passWord" type="password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </body>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios'
import { useRoute, useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
const route = useRoute();
const router = useRouter();
const form = reactive({
  userName: '',
  passWord: ''
})

const id=ref(0);

const onSubmit = () => {
  axios.get("/api/UserInfo/UserLogin", {
    params: {
      userName: form.userName,
      passWord: form.passWord
    }
  })
    .then(res => {
      if (res.data.code == 0) {
        ElMessage.success(res.data.message);
        // console.log(res.data.data.UserInfo)
        // alert(res.data.data)
        localStorage.setItem("token",res.data.data);
        localStorage.setItem("userName", form.userName)
        router.push({
          name: 'UserRoleList'
        })
      }
    })
    .catch(err => {
      console.log(err);
    })
}

onMounted(() => {

})
</script>

<style scoped>
@media (min-width: 200px) {
  body {
    display: grid;
    place-items: center;
  }
}
</style>